#include "YUVItem.h"
#include <QGuiApplication>
#include <QQmlEngine>
#include <QQuickWindow>
#include <QSGRendererInterface>
#include <QSurfaceFormat>
#include <QtQuick>

static void prepareApp()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
	QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
	QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
	QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#endif
	QCoreApplication::setOrganizationName("JaredTao");
	QCoreApplication::setOrganizationDomain("https://jaredtao.github.io");
	QCoreApplication::setApplicationName(appName);
	qWarning() << QCoreApplication::applicationName();
}

int main(int argc, char* argv[])
{
	prepareApp();
	QGuiApplication app(argc, argv);

	QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi);
	auto fmt = QSurfaceFormat::defaultFormat();
	fmt.setSamples(4);
	QSurfaceFormat::setDefaultFormat(fmt);

	qmlRegisterType<YUVItem>("YUV", 1, 0, "YUVItem");

	const QUrl url(qmlPath + QStringLiteral("main.qml"));

	QQuickView view;
	view.setResizeMode(QQuickView::SizeRootObjectToView);
#ifdef imgPath
	view.rootContext()->setContextProperty("imgPath", imgPath);
#endif
#ifdef resPath
	view.rootContext()->setContextProperty("resPath", resPath);
#endif
	view.resize(800, 600);
	view.setSource(url);
	view.show();

	return app.exec();
}
